/*******************************************************************************
Last update: March 23, 2023 
********************************************************************************/

cls
clear all
local dir "~\Dropbox\Working Papers\Distinction Effect"
cd "`dir'"

qui do "Does\Data Processing\0. Cleaning Programs.do"

/*******************************************************************************/

cls
clear all
local dir "~\Dropbox\Working Papers\Signaling Skills"
cd "`dir'"

use "Data\Intermediates\OLE_2007_2016.dta", clear

//Graduation Year Undergraduate Degree
tostring fst_grad, gen(year_grad)
replace year_grad = substr(year_grad, 1, 4)
destring year_grad, replace

//Graduation Year Postgraduate Degree
tostring fst_g_gradsch, gen(year_gradsch)
replace year_gradsch = substr(year_gradsch, 1, 4)
destring year_gradsch, replace

//Sample Restriction 
drop if year_grad == .
drop if year_gradsch <= year_grad

//Program
destring ole_gradtime1 ole_gradtime2, replace
gen programcode = ole_programcode1 if ole_gradtime1==fst_grad 
replace programcode = ole_programcode2 if ole_gradtime2==fst_grad & programcode == ""
replace programcode = ole_programcode3 if regexm(ole_gradtime3, ",") == 0 & programcode == ""
drop if programcode == ""

//Program Level
gen aux = ole_programlevel1 if ole_programcode1==programcode
bys programcode : egen program_level = mode(aux)
drop aux

//Restrict Sample to 4Y Programs
keep if program_level == "6"

gen field_code = ole_programfield1 if ole_gradtime1==fst_grad 
replace field_code = ole_programfield2 if ole_gradtime2==fst_grad & field_code == ""
replace field_code = ole_programfield3 if regexm(ole_gradtime3, ",") == 0 & field_code == ""
drop if field_code  == ""

keep national_id* year_grad field_code ole_ciiu_???? ole_formalworker_????

reshape long ole_ciiu_ ole_formalworker_, i(national_id*) j(year)
keep if year >= year_grad
keep if year_grad <= 2013
keep if ole_formalworker_ == 1
drop ole_formalworker_
drop if ole_ciiu_ == .

rename ole_ciiu ciiu

merge m:1 ciiu using "Data\Intermediates\IndystryCodes_CIIU3_31.dta", keepusing(industry_code*)
keep if _merge == 3
drop _merge
drop industry_code3 industry_code31

//Worker's Industry
drop if ciiu == .

//Field's Industry
unique ciiu, by(field_code) gen(num_industries_field)
drop if num_industries_field == .

keep field_code num_industries_field

destring field_code, replace
drop if field_code <= 0

save "Data/Finals/SkillsTransferability.dta", replace